﻿@using Microsoft.AspNetCore.Localization
@using SimplCommerce.Infrastructure

@inject IViewLocalizer Localizer

@{
    var requestCulture = Context.Features.Get<IRequestCultureFeature>();
    var availableCultures = GlobalConfiguration.SimpleCultures;
}

@if (availableCultures.Count() > 1)
{
<li class="nav-item dropdown">
    <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown">
        Language (@requestCulture.RequestCulture.UICulture.Name)
        <span class="caret"></span>
    </a>
    <ul class="dropdown-menu lang-selector">
        @foreach (var lang in availableCultures)
        {
            if (lang.Id == requestCulture.RequestCulture.UICulture.Name)
            {
                <li class="dropdown-item"><a href="#" data-value="@lang.Id">@lang.Name <span class="glyphicon glyphicon-ok" aria-hidden="true"></span></a></li>
            }
            else
            {
                <li class="dropdown-item"><a href="#" data-value="@lang.Id">@lang.Name</a></li>
            }
        }
    </ul>
    <form asp-controller="Localization" asp-action="SetLanguage" asp-route-returnUrl="@Context.Request.Path"
                method="post" id="lang-form" role="form">
        <input type="hidden" name="culture" value="@requestCulture.RequestCulture.UICulture.Name" />
    </form>
</li>
}
